<?php /*
	
*/ ?>
<?php include("system/config.inc.php");
$donotinclude = 1;
// IF admin is not logged in then it will redirect to the adminlogin page.
if(!isset($_SESSION['adminuserid']))
{
	header("location:index.php?msg=logfirst");
	die();
}

if(isset($_REQUEST['proid']) && trim($_REQUEST['proid']) != "")
{
	
	if(isset($_REQUEST['Submit']) && trim($_REQUEST['Submit']) == "Update")
	   {
	   			$proid = $_REQUEST['proid'];
				$sqld="delete from tblrelatedproduct where intprodid='$proid'";
				$delete=mysql_query($sqld);
				$check=$_REQUEST['check'];
				foreach($check as $chk)
				{
					$upd="INSERT INTO `tblrelatedproduct`	 
							(`intprodid`,`intrelatedid`)
							  VALUES ('$proid','$chk')";	
					$sql=$obj_db->insert($upd);
				}
				header("location:product.php?msg=addtorelate");
				die();
		}
}		
?>
<?php include("inc/header.php");?>
<body>

 <form name="special" action="addtorelated.php?proid=<?php echo $_REQUEST['proid'];?>" method="post">	
<table width="80%" border="0" align="center" cellpadding="0" cellspacing="1" class="middlebackground">
  <tr>
    <td colspan="3" valign="top" align="center"><?php include(INC."top.inc.php");?></td>
  </tr>
  <tr>
    <td width="2%">&nbsp;</td>
    <td width="96%"><table width="70%" border="0" align="center" cellpadding="0" cellspacing="0" class="border">
      <tr>
        <td colspan="4" class="bg1"><strong>Add Related Product To</strong>:
		<?php 
		
		if(isset($_REQUEST['proid']) && trim($_REQUEST['proid']) != "")
			{
				
				$proid = $_REQUEST['proid'];
			
			
		$sql16="select * from tblproddesc where `intid`='$proid'";
			
		
		$pr = $obj_db->select($sql16);
		if(count($pr)>0)
		{
			echo $pr[0]['varprodname'];
				
		?>  <br /><br /></td>
        <td align="center" class="bg1"><a href="#" title="Click Here to Go Back!" onClick="history.go(-1);" class="fntstyle">Go Back!</a></td>
      </tr>
		<?php 
		
			/**************************************
					PAGING CODE START
			**************************************/
			$rowperpage=10;
			$tablename="tblproducts";
			$per_page_keywords= "intprodid!='$proid'";
			$per_page_sorts= "";
			include("system/paging.inc.php");
	
			/**************************************
					PAGING CODE ENDING
			**************************************/
	
		
			$sql = "select * 
			from  ".$tablename."
			where ".$per_page_keywords."
			Limit ".($page_no*$row_per_page).",".$row_per_page;
			

			$respro=$obj_db->select($sql);
			if(count($respro)>0)
			{
				for($p=0;$p<count($respro);$p++)
				{
					$id= $respro[$p]['intprodid'];
					
				
		?>
        <tr>
          <td width="4%">&nbsp;</td>
          <td></td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
        </tr>
        <tr>
        <td>&nbsp;</td>
		
        <td width="56%">
		
		
		<input name="check[]" type="checkbox" id="check[]" value="<?php echo $id;?>"<?php 
		 
			$sql6="select * from tblrelatedproduct where intprodid='$proid' AND 
			intrelatedid = '$id'";
			$reschk = $obj_db->select($sql6);
			if(count($reschk)>0)
			{
				for($i=0;$i<count($reschk);$i++)
				{
					$iid=$reschk[$i]['intprodid'];
	
					if($iid == $proid){ echo "checked";} else{echo "";}
										
				}

			}
		?>/> 
		    <?php
			  $sql6="select * from tblproddesc where intid='$id'"; 
			  $resname = $obj_db->select($sql6);
			  if(count($resname)>0)
			  {
			  	for($pn=0;$pn<count($resname);$pn++)
				{
					echo $resname[$pn]['varprodname']." - ".$id;
				}
			  }	
			  ?></td>
        <td width="1%">&nbsp;</td>
        <td width="22%">&nbsp;</td>
        <td width="17%">&nbsp;</td>
      </tr>
	  <?php }}}}?>
        <tr>
          <td colspan="5" align="center">&nbsp;</td>
        </tr>
        <tr>
          <td colspan="5" align="center">
		  <?php pagindet_atbotttom_page($div_page_no,$page_no,$req_querystr,$total_db_rec,$row_per_page);?></td>
        </tr>
        <tr>
          <td colspan="5" align="center">&nbsp;</td>
        </tr>
        <tr> 
          <td colspan="5" align="center"><label>
            <input name="Submit" type="submit" class="btn" value="Update" onClick="return confirm('Are you sure want to link the product to this product?');"/>
          </label></td>
          </tr>
       
    </table></td>
    <td width="2%">&nbsp;</td>
  </tr>
  <tr>
    <td colspan="3" align="center"><?php include(INC."bottom.php");?></td>
  </tr>
</table>
</form>
</body>
</html>
